#include <gtest/gtest.h>
#include "../../common/directory.h"

TEST(DirectoryTest, OpenUnExistDir)
{
	asce::Directory dir;
	EXPECT_FALSE(dir.Open("unexist"));
	EXPECT_FALSE(dir.valid());
}

TEST(DirectoryTest, OpenExistDir)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
}

TEST(DirectoryTest, OpenDirMoreTimes)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_FALSE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_FALSE(dir.Open("unexist"));
	EXPECT_TRUE(dir.valid());
}

TEST(DirectoryTest, CloseInvalidDir)
{
	asce::Directory dir;
	EXPECT_FALSE(dir.Open("unexist"));
	EXPECT_FALSE(dir.valid());
	EXPECT_FALSE(dir.Close());
}

TEST(DirectoryTest, CloseValidDir)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_TRUE(dir.Close());
	EXPECT_FALSE(dir.valid());
}

TEST(DirectoryTest, FindExistChildDir)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_TRUE(dir.FindChildDir("childdir"));
}

TEST(DirectoryTest, FindUnExistChildDir)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_FALSE(dir.FindChildDir("unexist"));
}

TEST(DirectoryTest, FindExistFile)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_TRUE(dir.FindFile("test.txt"));
}

TEST(DirectoryTest, FindUnExistFile)
{
	asce::Directory dir;
	EXPECT_TRUE(dir.Open("test"));
	EXPECT_TRUE(dir.valid());
	EXPECT_TRUE(dir.FindFile("unexist.txt"));
}
